<template>
	<view class="top" :style="{'padding-top': paddingTop}">
		<view class="left">

			<!-- #ifndef MP-WEIXIN-->
			<view class="avatar">
				<image mode="aspectFill" src="https://www.cdn.kxcdedu.top/image/default/B96815CBEFBE481984ECAF4B1330CE67-6-2.png">
					</image>
			</view>
			<!-- #endif -->

			<view class="search" @click="toSearch" :style="{'height': inputHeight}">
				<uni-icons style="margin-left: 20rpx;margin-right: 10rpx;" type="search" size="25" color="#b8b8b8">
				</uni-icons>
				<view style="color: #b8b8b8;">搜索候浪内容</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "top-card",
		data() {
			return {
				paddingTop: null,
				inputHeight: "70rpx"
			};
		},
		mounted() {
			// #ifdef MP-WEIXIN
			// 1.获取屏幕可使用宽度
			let windowWidth = uni.getSystemInfoSync().windowWidth;
			// 2.获取状态栏高度
			const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			// 3.获取胶囊按钮位置信息
			const menuButton = uni.getMenuButtonBoundingClientRect();
			
			// 4.计算出导航栏高度  换算成rpx
			let navHeight = (menuButton.height + (menuButton.top - statusBarHeight) * 2) * (750 / windowWidth);
			
			// // 5.导航栏与状态栏拉开距离  margin-top: statusBarTop + 'rpx'; 
			this.inputHeight = menuButton.height * (750 / windowWidth) + 'rpx';
			this.paddingTop = menuButton.top* (750 / windowWidth) -2 + 'rpx';
					
			// #endif
		},
		methods: {
			changeFollowStatus() {
				this.$api.changeUserFollowStatus({
					id: this.userInfo.id
				}).then(() => {
					console.log("改变元素属性")
					this.userInfo.isFollowed = !this.userInfo.isFollowed
				})
			},
			toSearch() {
				uni.navigateTo({
					url: '/pages/search/search?type=0'
				})
			},
			toMessage() {
				uni.navigateTo({
					url: '/pages_message/message'
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.top {
		width: 690rpx;
		height: 70rpx;

		padding: 105rpx 30rpx 10rpx 30rpx;
		
		// #ifdef H5
		padding-top: 40rpx;
		// #endif

		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		// background-color: #ffffff;

		z-index: 1;
		position: absolute;

		.left {

			display: flex;
			flex-direction: row;
			align-items: center;

			.avatar {
				width: 70rpx;
				height: 70rpx;
				border-radius: 50rpx;
				margin-right: 30rpx;
				overflow: hidden;
				border: solid #FFFFFF;
			}

			.search {
				margin-right: 30rpx;
				height: 70rpx;
				width: 580rpx;

				// #ifdef MP-WEIXIN
				width: 500rpx;
				// #endif
				display: flex;
				flex-direction: row;
				align-items: center;
				border-radius: 50rpx;

				background-color: #FFFFFF;
			}

		}

		.right {
			display: flex;
			flex-direction: row;
			justify-content: flex-end;
			align-items: center;

			// #ifdef MP-WEIXIN
			margin-right: 180rpx;
			// #endif
		}


	}

	image {
		width: 100%;
		height: 100%;
	}
</style>
